// import Notify from '../../../miniprogram_npm/@vant/weapp/notify/notify';
let item = '',
    DataResult = {}
Page({

    /**
     * 页面的初始数据
     */
    data: {
        DataList: [],
        activeKey: 0,
        sumNum: 0,
        successShow: false,
        checkShow: false,
        failShow: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    async onShow() {
        this.getList()
        let { // sumNum
            result
        } = await wx.cloud.callFunction({
            name: 'getAudioCountList'
        })
        this.setData({
            sumNum: result.length || 0
        })
    },

    againUp(e) {
        item = e.currentTarget.dataset.val;
        console.log(item)
        wx.setStorageSync('again_up', item)
        wx.navigateTo({
            url: '/pages/audio/upWordAudio/upWordAudio?id=' + item._id + "&content=" + item.content + "&uptype=" + 'againUp',
        })
    },

    wordDetail(e) {
        console.log(e)
        let itm = e.currentTarget.dataset.val
        wx.navigateTo({ // 暂定为跳转提示页面
            url: '/pages/dictionary/wordDetail/wordDetail?id=' + itm._id + '&content=' + itm.content,
        })
    },

    toCnt() {
        wx.navigateTo({
            url: '/pages/audio/audioCount/audioCount',
        })
    },

    // 获取数据
    async getList() {
        let {
            result
        } = await wx.cloud.callFunction({
            name: "getDictWord",
            data: {
                type: "statusWord",
                openid: wx.getStorageSync('userInfo').openid
            }
        })
        this.setData({
            DataList: result.success
        })
        console.log(result)
        DataResult = result

        // 利用缓存的数据与当前请求数据比较，确认是否显示未读标识
        new Promise(() => {
            if (wx.getStorageSync('audioStatusCun')) {
                // console.log('DataResult',DataResult)
                let count = wx.getStorageSync('audioStatusCun')
                if (result.fail.length > count.fail) {
                    this.setData({
                        failShow: true
                    })
                }
            }
        })

        await wx.setStorageSync('audioStatusCun', {
            success: DataResult.success.length,
            fail: DataResult.fail.length,
            check: DataResult.check.length
            // })
        })

    },

    onChange(e) {
        // Notify({ type: 'primary', message: event.detail });
        let idx = e.detail
        if (idx == 0) {
            this.setData({
                DataList: DataResult.success,
            })
        } else if (idx == 1) {
            this.setData({
                DataList: DataResult.check,
            })
        } else if (idx == 2) {
            this.setData({
                DataList: DataResult.fail,
                failShow: false
            })
        }
    },
})